package com.ggh.jinjilive.dialog.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemCreateRoomBinding;
import com.ggh.jinjilive.databinding.ItemLiveShrinkageBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.live.ShrinkageMobile;

import java.util.List;

public class LiveShrinkageAdapter extends RecyclerView.Adapter<LiveShrinkageAdapter.ItemViewHolder> {
    private List<ShrinkageMobile> shrinkageMobileList;


    public void setAdd(List<ShrinkageMobile> shrinkageMobileList) {
        this.shrinkageMobileList = shrinkageMobileList;
        notifyDataSetChanged();
    }

    private AddItemOnClickListener addItemOnClickListener;

    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemLiveShrinkageBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_live_shrinkage, parent, false);
        return new ItemViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull LiveShrinkageAdapter.ItemViewHolder holder, int position) {
        ShrinkageMobile shrinkageMobile = shrinkageMobileList.get(position);
        if(null != shrinkageMobile){
            holder.binding.imgPicture.setImageResource(shrinkageMobile.getPicture());
            holder.binding.tvName.setText(shrinkageMobile.getName());
            holder.binding.llLiveShrinkage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(null != addItemOnClickListener){
                        addItemOnClickListener.onSkipClicked(position,shrinkageMobile);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return null == shrinkageMobileList ? 0 : shrinkageMobileList.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemLiveShrinkageBinding binding;

        public ItemViewHolder(@NonNull ItemLiveShrinkageBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}